/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JpnlFinalDerivatives.java
 *
 * Created on 08/06/2010, 16:58:43
 */
package systole.view.tabs.finalsegment;

import java.awt.BorderLayout;
import org.jdesktop.application.Action;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import systole.view.charts.XYChart;

/**
 *
 * @author user
 */
public class JpnlFinalDerivatives extends javax.swing.JPanel {

    /**
     *
     */
    private static final long serialVersionUID = 5531973399667834247L;
    private ChartPanel chart;

    /** Creates new form JpnlFinalDerivatives */
    public JpnlFinalDerivatives() {
        initComponents();
    }

    /**
     * 
     * @param derivatives
     */
    public void loadDerivatives(XYChart derivatives) {
        this.jPnlDerivativesChart.removeAll();
        this.jPnlDerivativesChart.setLayout(new BorderLayout());
        derivatives.setShowLegend(true);
        this.chart = derivatives.plot();
        XYItemRenderer rend = this.chart.getChart().getXYPlot().getRenderer();
        rend.setSeriesVisible(3, false, true);
        rend.setSeriesVisible(4, false, true);
        this.getJPnlDerivativesChart().add(this.chart, BorderLayout.CENTER);
        this.revalidate();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPnlDerivativesChart = new javax.swing.JPanel();
        jPnlToggleDerivatives = new javax.swing.JPanel();
        chkDerivative1 = new javax.swing.JCheckBox();
        chkDerivative2 = new javax.swing.JCheckBox();
        chkDerivative3 = new javax.swing.JCheckBox();
        chkDerivative4 = new javax.swing.JCheckBox();
        jPnlTop = new javax.swing.JPanel();
        jPnlRigth = new javax.swing.JPanel();
        jPnlLeft = new javax.swing.JPanel();

        setName("Form"); // NOI18N
        setRequestFocusEnabled(false);
        setLayout(new java.awt.BorderLayout());

        jPnlDerivativesChart.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPnlDerivativesChart.setName("jPnlDerivativesChart"); // NOI18N
        jPnlDerivativesChart.setLayout(new java.awt.BorderLayout());
        add(jPnlDerivativesChart, java.awt.BorderLayout.CENTER);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getResourceMap(JpnlFinalDerivatives.class);
        jPnlToggleDerivatives.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPnlToggleDerivatives.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jPnlToggleDerivatives.border.titleFont"))); // NOI18N
        jPnlToggleDerivatives.setName("jPnlToggleDerivatives"); // NOI18N
        jPnlToggleDerivatives.setPreferredSize(new java.awt.Dimension(454, 60));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getActionMap(JpnlFinalDerivatives.class, this);
        chkDerivative1.setAction(actionMap.get("toggleFirst")); // NOI18N
        chkDerivative1.setSelected(true);
        chkDerivative1.setText(resourceMap.getString("chkDerivative1.text")); // NOI18N
        chkDerivative1.setName("chkDerivative1"); // NOI18N

        chkDerivative2.setAction(actionMap.get("toggleSecond")); // NOI18N
        chkDerivative2.setSelected(true);
        chkDerivative2.setText(resourceMap.getString("chkDerivative2.text")); // NOI18N
        chkDerivative2.setName("chkDerivative2"); // NOI18N

        chkDerivative3.setAction(actionMap.get("toggleThird")); // NOI18N
        chkDerivative3.setText(resourceMap.getString("chkDerivative3.text")); // NOI18N
        chkDerivative3.setName("chkDerivative3"); // NOI18N

        chkDerivative4.setAction(actionMap.get("toggleFourth")); // NOI18N
        chkDerivative4.setText(resourceMap.getString("chkDerivative4.text")); // NOI18N
        chkDerivative4.setName("chkDerivative4"); // NOI18N

        javax.swing.GroupLayout jPnlToggleDerivativesLayout = new javax.swing.GroupLayout(jPnlToggleDerivatives);
        jPnlToggleDerivatives.setLayout(jPnlToggleDerivativesLayout);
        jPnlToggleDerivativesLayout.setHorizontalGroup(
            jPnlToggleDerivativesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlToggleDerivativesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chkDerivative1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkDerivative2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkDerivative3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkDerivative4)
                .addContainerGap(54, Short.MAX_VALUE))
        );
        jPnlToggleDerivativesLayout.setVerticalGroup(
            jPnlToggleDerivativesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlToggleDerivativesLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPnlToggleDerivativesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chkDerivative1)
                    .addComponent(chkDerivative2)
                    .addComponent(chkDerivative3)
                    .addComponent(chkDerivative4))
                .addContainerGap())
        );

        add(jPnlToggleDerivatives, java.awt.BorderLayout.SOUTH);

        jPnlTop.setName("jPnlTop"); // NOI18N
        jPnlTop.setPreferredSize(new java.awt.Dimension(478, 5));
        jPnlTop.setLayout(new java.awt.BorderLayout());
        add(jPnlTop, java.awt.BorderLayout.NORTH);

        jPnlRigth.setName("jPnlRigth"); // NOI18N
        jPnlRigth.setPreferredSize(new java.awt.Dimension(10, 250));

        javax.swing.GroupLayout jPnlRigthLayout = new javax.swing.GroupLayout(jPnlRigth);
        jPnlRigth.setLayout(jPnlRigthLayout);
        jPnlRigthLayout.setHorizontalGroup(
            jPnlRigthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPnlRigthLayout.setVerticalGroup(
            jPnlRigthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 235, Short.MAX_VALUE)
        );

        add(jPnlRigth, java.awt.BorderLayout.LINE_END);

        jPnlLeft.setName("jPnlLeft"); // NOI18N
        jPnlLeft.setPreferredSize(new java.awt.Dimension(10, 250));

        javax.swing.GroupLayout jPnlLeftLayout = new javax.swing.GroupLayout(jPnlLeft);
        jPnlLeft.setLayout(jPnlLeftLayout);
        jPnlLeftLayout.setHorizontalGroup(
            jPnlLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPnlLeftLayout.setVerticalGroup(
            jPnlLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 235, Short.MAX_VALUE)
        );

        add(jPnlLeft, java.awt.BorderLayout.LINE_START);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void toggleFirst() {
        XYItemRenderer rend = this.chart.getChart().getXYPlot().getRenderer();
        rend.setSeriesVisible(1, chkDerivative1.isSelected(), true);
    }

    @Action
    public void toggleSecond() {
        XYItemRenderer rend = this.chart.getChart().getXYPlot().getRenderer();
        rend.setSeriesVisible(2, chkDerivative2.isSelected(), true);
    }

    @Action
    public void toggleThird() {
        XYItemRenderer rend = this.chart.getChart().getXYPlot().getRenderer();
        rend.setSeriesVisible(3, chkDerivative3.isSelected(), true);
    }

    @Action
    public void toggleFourth() {
        XYItemRenderer rend = this.chart.getChart().getXYPlot().getRenderer();
        rend.setSeriesVisible(4, chkDerivative4.isSelected(), true);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox chkDerivative1;
    private javax.swing.JCheckBox chkDerivative2;
    private javax.swing.JCheckBox chkDerivative3;
    private javax.swing.JCheckBox chkDerivative4;
    private javax.swing.JPanel jPnlDerivativesChart;
    private javax.swing.JPanel jPnlLeft;
    private javax.swing.JPanel jPnlRigth;
    private javax.swing.JPanel jPnlToggleDerivatives;
    private javax.swing.JPanel jPnlTop;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the jPnlDerivativesChart
     */
    public javax.swing.JPanel getJPnlDerivativesChart() {
        return jPnlDerivativesChart;
    }

    /**
     * @param jPnlDerivativesChart the jPnlDerivativesChart to set
     */
    public void setJPnlDerivativesChart(javax.swing.JPanel jPnlDerivativesChart) {
        this.jPnlDerivativesChart = jPnlDerivativesChart;
    }

    /**
     * @return the jPnlToggleDerivatives
     */
    public javax.swing.JPanel getJPnlToggleDerivatives() {
        return jPnlToggleDerivatives;
    }

    /**
     * @param jPnlToggleDerivatives the jPnlToggleDerivatives to set
     */
    public void setJPnlToggleDerivatives(javax.swing.JPanel jPnlToggleDerivatives) {
        this.jPnlToggleDerivatives = jPnlToggleDerivatives;
    }
}
